import axios from 'axios'
import { ElMessage } from 'element-plus'

const http = axios.create({
  baseURL:
    import.meta.env.VITE_PRODUCTION === 'dev'
      ? '/api'
      : import.meta.env.VITE_PRODUCTION === 'test'
        ? '/api-test'
        : ''
})
http.interceptors.response.use((response) => {
  const res = response.data
  if (res.code === 200) {
    return res.data
  } else {
    ElMessage.error('请求错误，请重试')
    return Promise.reject(res.msg)
  }
})
export default http
